using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Management;

namespace PodInvaders
{
	public class Invader
	{
		public delegate void IPodFoundHandler(string Name, string Drive);

//		public event IPodFoundHandler IpodFound;

		public List<IPod> FindIpods()
		{
			List<string> drives = new List<string>();
			ArrayList hdCollection = new ArrayList();

			ManagementObjectSearcher searcher = new
				ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

			string model;

			foreach (ManagementObject drive in searcher.Get())
			{
				model = drive["Model"].ToString();

				if (model.IndexOf("Apple iPod USB Device") == -1)
					continue;

				ManagementObjectCollection partitions = drive.GetRelated("Win32_DiskPartition");

				foreach (ManagementObject partition in partitions)
				{
					foreach (ManagementBaseObject logicalDisk in partition.GetRelated("Win32_LogicalDisk"))
						drives.Add(logicalDisk["Name"].ToString());
				}
			}

			List<IPod> ipods = new List<IPod>(drives.Count);

			foreach (string drive in drives)
			{
				DriveInfo di = new DriveInfo(drive);
				ipods.Add(new IPod(di.VolumeLabel, drive));
			}

			return ipods;
		}
	}
}